//
//  LZPTImePicker.m
//  sr01sdkProject
//
//  Created by   on 2022/5/30.
//

#import "LZPTImePicker.h"

@implementation LZPTImePicker
{
    NSArray<NSArray *> * _compoments;
    NSMutableArray<NSNumber *> * _hours;
    NSMutableArray<NSNumber *> * _minutes;
    NSMutableArray<NSNumber *> * _seconds;

    NSNumber *_curHor, *_curMin, *_curSec;
}

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self dataInit];
        self.delegate = self;
        self.dataSource = self;
    }
    return self;
}

-(void)dataInit {
    _hours = [NSMutableArray arrayWithCapacity:24];
    _minutes = [NSMutableArray arrayWithCapacity:60];
    _seconds = [NSMutableArray arrayWithCapacity:60];
    for (int i = 0; i < 24; i++) {
        _hours[i] = @(i);
    }
    
    for (int i = 0; i < 60; i++) {
        _minutes[i] = @(i);
    }
    
    for (int i = 0; i < 60; i++) {
        _seconds[i] = @(i);
    }
    
    _compoments = @[_hours, _minutes, _seconds];
    
}


-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return _compoments.count;
}



-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    return [NSString stringWithFormat:@"%.2d", [_compoments[component][row] intValue] ];
}



-(CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component
{
    return 35;
}

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    
    switch (component) {
        case 0:
        {
            _curHor = _compoments[component][row];
        }
            break;
        case 1:
        {
            _curMin = _compoments[component][row];
        }
            break;
        case 2:
        {
            _curSec = _compoments[component][row];
        }
            break;
            
        default:
            break;
    }
    
    if (self.callBack) {
        self.callBack(_curHor, _curMin, _curSec);
    }
    
}



- (NSInteger)pickerView:(nonnull UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
    return _compoments[component].count;
}



@end
